D i m   a r r R o w Q u e s t i o n s   =   S u r v e y . Q u e s t i o n s . F i l t e r B y T a g ( " D e m o g r a p h i c s " ) 
 D i m   a r r C o l Q u e s t i o n s   =   S u r v e y . Q u e s t i o n s . F i l t e r B y T a g ( " W a v e " ) 
 
 D i m   r e s P o r t f o l i o   A s   P o r t f o l i o 
 D i m   r e s I t e m   A s   P o r t f o l i o I t e m 
 D i m   P r o f i l e C o l u m n   a s   P r o f i l e 
 D i m   P r o f i l e R o w   a s   P r o f i l e 
 
 D i m   i 
 F o r   i   =   1   t o   a r r R o w Q u e s t i o n s . C o u n t 
     P r o f i l e R o w . a d d ( a r r R o w Q u e s t i o n s [ i ] )   '   A d d   a l l   ' D e m o g r a p h i c s '   t a g g e d   q u e s t i o n s   t o   t h e   r o w s 
 N e x t   i 
 
 D i m   j 
 F o r   j   =   1   t o   a r r C o l Q u e s t i o n s . C o u n t 
     P r o f i l e C o l u m n . a d d ( a r r C o l Q u e s t i o n s [ j ] )   '   A d d   a l l   ' W a v e '   t a g g e d   q u e s t i o n s   t o   t h e   c o l u m n s 
 N e x t   j 
 
 ' A d d   g r o u p e d   r e s p o n s e s   ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 D i m   n e t Q u e s L o y a l t y   a s   P r o f i l e Q u e s t i o n 
 n e t Q u e s L o y a l t y . Q u e s t i o n   =   B 4   '   E x a m p l e   o f   u s i n g   s p e c i f i c   q u e s t i o n ,   p r e f e r   u s i n g   t a g s   t o   k e e p   t h e   s c r i p t   g e n e r i c   e . g .   t a g   q u e s t i o n s   a s   ' T B 2   7   s c a l e   f o r   N e t s / G r o u p s '   
 n e t Q u e s L o y a l t y . C l e a r ( ) 
 
 D i m   n e t R e s p T 2 B   a s   P r o f i l e I t e m   '   1 s t   G r o u p e d   r e s p o n s e 
 n e t R e s p T 2 B . C a p t i o n   =   " N E T   ( T 2 B ) :   L o y a l " 
 n e t R e s p T 2 B . T y p e   =   1 
 n e t Q u e s L o y a l t y . A d d ( n e t R e s p T 2 B ) 
 
 D i m   n e t R e s p B 2 B   a s   P r o f i l e I t e m   '   2 n d   g r o u p e d   r e s p o n s e 
 n e t R e s p B 2 B . C a p t i o n   =   " N E T   ( B 2 B ) :   N o t   l o y a l " 
 n e t R e s p B 2 B . T y p e   =   1 
 n e t Q u e s L o y a l t y . A d d ( n e t R e s p B 2 B ) 
 
 D i m   k   '   U s e   t o   l o o p   t h r o u g h   a l l   r e s p o n s e s   a n d   a d d   r e q u i r e d   o n e s   t o   t h e i r   g r o u p s 
 F o r   k   =   0   t o   n e t Q u e s L o y a l t y . Q u e s t i o n . R e s p o n s e s . C o u n t 
     D i m   m y R e s p o n s e s   a s   P r o f i l e I t e m 
     m y R e s p o n s e s . T y p e   =   0 
     m y R e s p o n s e s . R e s p o n s e   =   k 
     I f   k   i n   { 1 ; 2 }   T h e n   
         n e t Q u e s L o y a l t y . A d d ( m y R e s p o n s e s ,   n e t R e s p B 2 B ) 
     E l s e I f   k   i n   { 6 ; 7 }   T h e n   
         n e t Q u e s L o y a l t y . A d d ( m y R e s p o n s e s ,   n e t R e s p T 2 B ) 
     E n d i f 
     m y R e s p o n s e s . S e l e c t e d   =   F a l s e 
     n e t Q u e s L o y a l t y . A d d ( m y R e s p o n s e s ) 
 N e x t   k 
 
 ' A d d   c a l c u l a t e d   r e s p o n s e   ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 D i m   c a l c Q u e s W e e k D i f f   a s   P r o f i l e Q u e s t i o n 
 c a l c Q u e s W e e k D i f f . Q u e s t i o n   =   W e e k s   '   E x a m p l e   o f   u s i n g   s p e c i f i c   q u e s t i o n ,   p r e f e r   u s i n g   t a g s   t o   k e e p   t h e   s c r i p t   g e n e r i c   e . g .   t a g   q u e s t i o n s   a s   ' W a v e   q u e s t i o n s   ( c u r r e n t   -   p r e v i o u s ) '   
 
 D i m   h   '   A d d   v a r i a b l e ' s   r e s p o n s e s   a g a i n   s o   t h e   c a l c   r e s p o n s e   c a n   b e   a t   t h e   e n d   o f   t h e   l i s t 
 F o r   h   =   0   t o   c a l c Q u e s W e e k D i f f . Q u e s t i o n . R e s p o n s e s . C o u n t - 1 
     D i m   w e e k Q u e s R e s p s   a s   P r o f i l e I t e m 
     w e e k Q u e s R e s p s . T y p e   =   0 
     w e e k Q u e s R e s p s . R e s p o n s e   =   h 
     c a l c Q u e s W e e k D i f f . A d d ( w e e k Q u e s R e s p s ) 
 N e x t   h 
 
 D i m   n u m C u r r W e e k   =   W e e k s . R e s p o n s e s . C o u n t - 1   '   C u r r e n t   w e e k   i s   a l w a y s   t h e   l a s t   r e p o n s e   o f   t h e   v a r i a b l e   ( s u b t r a c t   1   t o   a c c o u n t   f o r   ' N o t   a s k e d '   c o d e ) 
 D i m   n u m P r e v W e e k   =   W e e k s . R e s p o n s e s . C o u n t - 2   '   P r e v i o u s   w e e k   i s   a l w a y s   o n e   r e s p o n s e   b e f o r e   ' C u r r e n t   w e e k ' 
 D i m   s t r C a l c R e s p S c r i p t   =   " { " +   n u m C u r r W e e k . T o S t r i n g ( )   + " }   -   { " +   n u m P r e v W e e k . T o S t r i n g ( )   + " } "     '   T h i s   g i v e s   u s   a   d y n a m i c   s c r i p t   w h i c h   w i l l   u p d a t e   i t s e l f   w i t h   a d d i t i o n   o f   n e w   w e e k   r e s p o n s e s 
 
 D i m   c a l c R e s p W e e k D i f f   a s   P r o f i l e I t e m 
 c a l c R e s p W e e k D i f f . C a p t i o n   =   " C u r r e n t   w a v e   -   P r e v i o u s   w a v e " 
 c a l c R e s p W e e k D i f f . T y p e   =   2 
 c a l c R e s p W e e k D i f f . S c r i p t   =   s t r C a l c R e s p S c r i p t 
 c a l c Q u e s W e e k D i f f . A d d ( c a l c R e s p W e e k D i f f ) 
 
 ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 P r o f i l e R o w . a d d ( n e t Q u e s L o y a l t y )   '   A d d   n e w   v a r i a b l e   w i t h   g r o u p e d   r e s p o n s e s   t o   r o w s 
 P r o f i l e C o l u m n . a d d ( c a l c Q u e s W e e k D i f f )   '   A d d   n e w   v a r i a b l e   w i t h   c a l c   r e s p o n s e s   t o   r o w s 
 ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
             r e s I t e m . S e t T y p e ( 1 ) 
 	     r e s I t e m . S e t T i t l e ( " D e m o g r a p h i c s   b y   W a v e " ) 
 	     r e s I t e m . T a b D e f . R e a d T a b T e m p l a t e ( " A s k i a   S i m p l e " ) 
     	     r e s I t e m . T a b D e f . R o w s . a d d ( P r o f i l e R o w )         
     	     r e s I t e m . T a b D e f . C o l u m n s . a d d ( P r o f i l e C o l u m n )         
             r e s P o r t f o l i o . a d d ( r e s I t e m ) 
 
 r e s P o r t f o l i o . S a v e ( S u r v e y . D i r e c t o r y   +   " 1 0 a .   A d d i n g   C a l c u l a t e d   &   G r o u p e d   R e s p o n s e s   U s i n g   S c r i p t . x m l " ) 
 r e s P o r t f o l i o . O p e n ( ) 